//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ww.springboot.boot.utils;

import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils;

public class SimpleStringUtil {
    public SimpleStringUtil() {
    }

    public static BigDecimal convertToBigDecimal(Object amount) {
        Double dbl = convertToDouble(amount, (Double)null);
        return dbl == null ? null : BigDecimal.valueOf(dbl);
    }

    public static Double convertToDouble(Object obj, Double dDefault) {
        try {
            return Double.parseDouble(clearNotNumber(convertToString(obj)));
        } catch (Exception var3) {
            return dDefault;
        }
    }

    public static String clearNotNumber(String strSrc) {
        if (isNullOrEmpty(strSrc)) {
            return "";
        } else {
            StringBuilder sbRslt = new StringBuilder();

            for(int i = 0; i < strSrc.length(); ++i) {
                if (strSrc.charAt(i) == '-' || strSrc.charAt(i) == '.' || (strSrc.charAt(i) + "").matches("\\d?")) {
                    sbRslt.append(strSrc.charAt(i));
                }
            }

            return sbRslt.toString();
        }
    }

    public static Integer convertToInteger(Object obj) {
        try {
            return Integer.parseInt(convertToString(obj));
        } catch (Exception var2) {
            return Integer.MIN_VALUE;
        }
    }

    public static Integer convertToInteger(Object obj, Integer defaltValue) {
        try {
            return Integer.parseInt(convertToString(obj));
        } catch (Exception var3) {
            return defaltValue;
        }
    }

    public static Long convertToLong(Object obj) {
        try {
            return Long.parseLong(convertToString(obj));
        } catch (Exception var2) {
            return Long.MIN_VALUE;
        }
    }

    public static Long convertToLong(Object obj, Long lDefault) {
        try {
            return Long.parseLong(convertToString(obj));
        } catch (Exception var3) {
            return lDefault;
        }
    }

    public static String convertToString(Object obj) {
        return obj == null ? "" : obj.toString();
    }

    public static String subStringRight(String strSrc, Integer iLength) {
        if (strSrc == null) {
            return "";
        } else if (iLength <= 0) {
            return "";
        } else {
            return strSrc.length() - iLength < 0 ? strSrc : strSrc.substring(strSrc.length() - iLength);
        }
    }

    public static Boolean stringEqualsIgnoreCase(String str1, String str2) {
        return addEmptyString(str1).equalsIgnoreCase(addEmptyString(str2));
    }

    public static Boolean stringEqualsIgnoreCaseObj(Object str1, Object str2) {
        return addEmptyString(str1).equalsIgnoreCase(addEmptyString(str2));
    }

    public static String addEmptyString(String str1) {
        return str1 == null ? "" : str1;
    }

    public static String addEmptyString(Object str1) {
        return str1 == null ? "" : str1 + "";
    }

    public static String newLine() {
        return System.getProperty("line.separator", "\r\n");
    }

    public static String trimPattern(String strSrc, String strPattern) {
        if (StringUtils.isBlank(strSrc)) {
            return strSrc;
        } else {
            return StringUtils.isBlank(strPattern) ? strSrc : strSrc.replaceAll("(^[" + strPattern + "]+)|([" + strPattern + "]+$)", "");
        }
    }

    public static boolean isNullOrEmpty(Object o) {
        if (o == null) {
            return true;
        } else {
            return o instanceof String ? StringUtils.isBlank((String)o) : false;
        }
    }
}
